package com.easy.common.util.file;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.Scanner;

public class FilePrint {


	public static String loadFilePrint(String realPath,String modename, Map map) {
        StringBuffer buf=new StringBuffer("");
		try {
            Scanner in = new Scanner(new File(realPath+"\\rptmode\\"+modename+".xls"));
            while (in.hasNextLine()) {
                String str = in.nextLine();
                StringBuffer sbuf=new StringBuffer("");
                while(true){
	                int spos=str.indexOf("${");
	                if(spos<0){
	                	sbuf.append(str);
	                	break;
	                }
	                int epos=str.indexOf("}",spos+1);
	                if(epos<0){
	                	sbuf.append(str);
	                	break;
	                }
	                sbuf.append(str.substring(0,spos));
	                String fld=str.substring(spos+2,epos);
	                try{
	                	Object object=map.get(fld);
	                	if(object!=null){
	                		sbuf.append((String)object);	                		
	                	}
	                	
	                }catch(Exception ex){}
	                str=str.substring(epos+1);
                }
                buf.append(sbuf);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
		return buf.toString();
	}
	public static String[] splitt(String str){
		String strr = str.trim();
		String[] abc = strr.split("/{/$\\w/}");
		System.out.println("length="+abc.length);
	    return abc;
	}
}
